﻿using System;
using System.Collections.Generic;
using System.Xml;
using Assist;
using Autodesk.Revit.DB;

namespace YJKOpeningCommon.OpeningProfile
{
	public class OpeningProfileRect : OpeningProfileBase
	{
		public override string GetCutSize(bool bIsFeet)
		{
			double val = this.m_cutWidth;
			double val2 = this.m_cutHeight;
			if (!bIsFeet)
			{
				val = AssistFunc.feetToMM(val);
				val2 = AssistFunc.feetToMM(val2);
			}
			return val.ToString("f0") + "X" + val2.ToString("f0");
		}

		public override string GetOpeningSize(bool bIsFeet)
		{
			double val = this.m_cutWidth + this.m_dExtendDist * 2.0;
			double val2 = this.m_cutHeight + this.m_dExtendDist * 2.0;
			if (!bIsFeet)
			{
				val = AssistFunc.feetToMM(val);
				val2 = AssistFunc.feetToMM(val2);
			}
			return val.ToString("f0") + "X" + val2.ToString("f0");
		}

		public override bool Export2XmlNode(XmlElement xmlNode)
		{
			try
			{
				if (!base.Export2XmlNode(xmlNode))
				{
					return false;
				}
				xmlNode.SetAttribute("Angle", this.m_angle.ToString());
				xmlNode.SetAttribute("CutHeight", this.m_cutHeight.ToString());
				xmlNode.SetAttribute("CutWidth", this.m_cutWidth.ToString());
			}
			catch
			{
				return false;
			}
			return true;
		}

		public override bool ImportByXmlNode(XmlNode xmlNode)
		{
			try
			{
				if (!base.ImportByXmlNode(xmlNode))
				{
					return false;
				}
				this.m_angle = Convert.ToDouble(xmlNode.Attributes["Angle"].Value);
				this.m_cutHeight = Convert.ToDouble(xmlNode.Attributes["CutHeight"].Value);
				this.m_cutWidth = Convert.ToDouble(xmlNode.Attributes["CutWidth"].Value);
			}
			catch
			{
				return false;
			}
			return true;
		}

		public override Outline GetSectionOutline3D()
		{
			return base.GetSectionOutline3D();
		}

		public override void GetProfileOutLineOnXOY(ref List<XYZ> lstPreviewPt, bool isAddExtend)
		{
			XYZ xyz = new XYZ(0.0, 0.0, 0.0);
			XYZ xyz2 = xyz + this.m_cutWidth / 2.0 * XYZ.BasisX.Negate() + XYZ.BasisY.Negate() * this.m_cutHeight / 2.0;
			XYZ xyz3 = xyz2 + XYZ.BasisX * this.m_cutWidth;
			if (isAddExtend)
			{
				double num = this.m_dTolerance + this.m_dExtendDist;
				xyz2 += num * XYZ.BasisY.Negate() + num * XYZ.BasisX.Negate();
				xyz3 += num * XYZ.BasisY.Negate() + num * XYZ.BasisX;
			}
			XYZ item = 2.0 * xyz - xyz3;
			XYZ item2 = 2.0 * xyz - xyz2;
			lstPreviewPt.Add(xyz2);
			lstPreviewPt.Add(xyz3);
			lstPreviewPt.Add(item2);
			lstPreviewPt.Add(item);
			new List<XYZ>();
			if (this.m_angle != 0.0)
			{
				Transform transform = Transform.CreateRotation(XYZ.BasisZ, this.m_angle);
				for (int i = 0; i < lstPreviewPt.Count; i++)
				{
					lstPreviewPt[i] = transform.OfPoint(lstPreviewPt[i]);
				}
			}
		}

		public double m_angle;

		public double m_cutHeight;

		public double m_cutWidth;
	}
}
